﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//Write a program that compares two char arrays lexicographically (letter by letter).

namespace _03CompareCharArrays
{
    class Program
    {
        static void Main(string[] args)
        {
            //Reading the first array from the console.
            Console.Write("ArrayOne size:");
            string strArrayOneSize = Console.ReadLine();
            int arrayOneSize = int.Parse(strArrayOneSize);
            char[] arrayOne = new char[arrayOneSize];
            for (int i = 0; i < arrayOne.Length; i++)
            {
                Console.Write("arrayOne[{0}]:", i);
                string toChar = Console.ReadLine();
                arrayOne[i] = char.Parse(toChar);
            }
            //Printing it out for verification.
            Console.Write("ArrayOne:");
            foreach (var item in arrayOne)
	        {
		        Console.Write(item + " ");
	        }
            Console.WriteLine();
            //Reading the second array from the console.
            Console.Write("ArrayTwo size:");
            string strArrayTwoSize = Console.ReadLine();
            int arrayTwoSize = int.Parse(strArrayTwoSize);
            char[] arrayTwo = new char[arrayTwoSize];
            for (int i = 0; i < arrayTwo.Length; i++)
            {
                Console.Write("arrayTwo[{0}]:", i);
                string toChar = Console.ReadLine();
                arrayTwo[i] = char.Parse(toChar);
            }
            //Printing it out for verification.
            Console.Write("ArrayTwo:");
            foreach (var item in arrayTwo)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            //Lexicographic comparison:
            if (arrayOneSize <= arrayTwoSize)
            {
                for (int i = 0; i < arrayOneSize; i++)
                {
                    if (arrayOne[i] < arrayTwo[i])
                    {
                        Console.WriteLine("Array one is first lexicographically.");
                        break;
                    }
                    else if (arrayOne[i] > arrayTwo[i])
                    {
                        Console.WriteLine("Array two is first lexicographically.");
                        break;
                    }
                    else if (arrayOne[i] == arrayTwo[i])
                    {
                        if ((i == (arrayOneSize - 1)) && (arrayOneSize == arrayTwoSize))
                        {
                            Console.WriteLine("The two arrays are exactly the same - size and lexicographically.");
                            break;
                        }
                        else if (i == (arrayOneSize - 1))
                        {
                            Console.WriteLine("Array one is first lexicographically.");
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                } 
            }
            if (arrayOneSize > arrayTwoSize)
            {
                for (int i = 0; i < arrayTwoSize; i++)
                {
                    if (arrayOne[i] < arrayTwo[i])
                    {
                        Console.WriteLine("Array one is first lexicographically.");
                        break;
                    }
                    else if (arrayOne[i] > arrayTwo[i])
                    {
                        Console.WriteLine("Array two is first lexicographically.");
                        break;
                    }
                    else if (arrayOne[i] == arrayTwo[i])
                    {
                        if ((i == (arrayTwoSize - 1)) && (arrayOneSize == arrayTwoSize))
                        {
                            Console.WriteLine("The two arrays are exactly the same - size and lexicographically.");
                            break;
                        }
                        else if (i == (arrayTwoSize - 1))
                        {
                            Console.WriteLine("Array two is first lexicographically.");
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
        }
    }
}
